<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            height: 2000px;
            width: 100px;
            background-color: mediumslateblue;
        }
    </style>
</head>
<body>
    <div>

    </div>
    <button>回到顶部</button>
    <script>
        var btnEle = document.querySelector("button");
        btnEle.onclick = function (){
            var timer = setInterval(function(){
                var hei = document.documentElement.scrollTop ; 
                console.log(hei <= 0);
                if( hei <= 0 ) {
                    clearInterval(timer);
                } else {
                    document.documentElement.scrollTop = hei - 10 ;
                }
            },10);
        }
    </script>
</body>
</html>